<!--
 * @Author: huang liang miao 1127255342@qq.com
 * @Date: 2025-01-07 17:08:35
 * @LastEditors: huang liang miao 1127255342@qq.com
 * @LastEditTime: 2025-01-16 11:21:40
 * @FilePath: \dcy-webd:\webCode\dcyCode\scientific_research_manager_web\src\components\AchievementDetails\Edit.vue
 * @Description: 编辑分数
-->

<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { updateScoreReq } from "@/api/resultsManagement/assessmentReward/index"

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  researchScoreTitle: {
    type: String,
    default: '',
  },
  score: {
    type: String,
    default: '',
  },
  curId: {
    type: String,
    default: '',
  },
  scoreType: {
    type: Number, // 1、科研分， 2、奖励积分
    default: 1,
  },
})
const emits = defineEmits(['close'])
const score = ref(Number(props.score))

// 编辑
const { run: updateScore, loading } = useRequest(updateScoreReq, {
  // false 为自动执行
  manual: true,
  // 请求成功
  onSuccess: () => {
    ElMessage({
      message: '编辑成功',
      type: 'success',
    })
    emits('close', true)
  },
})
function submit(){
  updateScore({
    id: props.curId,
    score: score.value,
    rewardFlag: props.scoreType === 2
  })
}
</script>

<template>
  <el-dialog
    v-model="props.visible"
    :title="`编辑${props.researchScoreTitle}`"
    width="460"
    :align-center="true"
    :close-on-click-modal="false"
    @close="emits('close')"
  >
    <div class="py-[14px] text-center">
      <span>是否确认修改{{props.researchScoreTitle}}为 </span>
      <el-input-number v-model.trim="score" placeholder="请输入分数" :controls="false" :min="0" :max="9999.99" :precision="2" class="score" /> ？
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="emits('close')">取消</el-button>
        <el-button type="primary" :loading="loading" @click="submit">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.score{
  @apply: w-[100px];
}
</style>